package com.hsmpay.mobile.service.message.impl;

import com.hsmpay.common.service.impl.BaseServiceSupport;
import com.hsmpay.mobile.dao.message.LoginMessageDao;
import com.hsmpay.mobile.pojo.message.LoginMessage;
import com.hsmpay.mobile.service.message.LoginMessageService;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 登录消息接口 loginMassageService
 * 对应数据层 loginMessageDao
 *
 * @param <Entity>
 * @param <Query>
 * @author 颜铃璋
 * @date 2013-9-29
 */
@Repository("loginMessageService")
public class LoginMessageServiceImpl extends BaseServiceSupport<LoginMessage, Long> implements LoginMessageService<LoginMessage, Long> {
    @Resource(name = "loginMessageDao")
    private LoginMessageDao<LoginMessage, Long> loginMessageDao;

    /**
     * 根据终端ID 获取公共消息
     *
     * @param terminalId
     * @param roleId
     * @return
     * @throws Exception
     */
    public List<LoginMessage> searchLoginSystemMsg(Long terminalId, Long roleId) throws Exception {
        LoginMessage msg = new LoginMessage();
        Date date = new Date();
        msg.setOtherParam(" (TERMINALID = 0 OR TERMINALID = " + terminalId + ") AND (ROLEID = 0 OR ROLEID = " + roleId + ")");//包括 全选的终端ID
        //msg.setRoleId(roleId);
        msg.setStatus(1);//消息状态 1 生效
        msg.setType(1);// 1 系统消息  2 个人消息
        msg.setInvalidTimeLong(date.getTime());
        return loginMessageDao.searchEntityList(msg);
    }

    /**
     * 根据终端ID 获取个人消息
     *
     * @param terminalId
     * @param roleId
     * @param userId
     * @return
     * @throws Exception
     */
    public List<LoginMessage> searchLoginPersonalMsg(Long terminalId, Long roleId, Long userId) throws Exception {
        LoginMessage msg = new LoginMessage();
        Date date = new Date();
        msg.setOtherParam(" (TERMINALID = 0 OR TERMINALID = " + terminalId + ") AND (ROLEID = 0 OR ROLEID = " + roleId + ")");//包括 全选的终端ID
        //msg.setRoleId(roleId);
        msg.setStatus(1);//消息状态 1 生效
        msg.setType(2);// 1 系统消息  2 个人消息
        msg.setUserId(userId);//用户Id
        msg.setInvalidTimeLong(date.getTime());//结束时间
        return loginMessageDao.searchEntityList(msg);
    }

    //---------------------set get start--------------------
    //---------------------set get end----------------------
}
